﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Gaea.CodeFirst
{
    public class GetTableInfo : GaeaBasicPower
    {
        public static async Task<Dictionary<string, string>> GetTableField<T>() where T : class
        {
            PropertyInfo[] propertyInfo = typeof(T).GetProperties();         
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            foreach (var item in propertyInfo)
            {
                var type = item.PropertyType.Name;
                keyValuePairs.Add(item.Name, type);
            }
            return keyValuePairs;
        }

        public void CreateTable<T>() where T : class
        {
            PropertyInfo[] propertyInfo = typeof(T).GetProperties();
            string ColumnSql = "";
            foreach (var item in propertyInfo)
            {
                var column_name = item.Name;
                var column_type = item.PropertyType.Name;
                if (column_type == "String")
                {
                    column_type = "varchar(50)";
                }
                else if (column_type == "Int32")
                {
                    column_type = "int";
                }
                ColumnSql+= column_name + column_type+",";
            }
            ColumnSql = ColumnSql.Substring(0, ColumnSql.Length - 1);
            //var sql = "CREATE TABLE " + T + " ( id int not null primary key auto_increment," + ColumnSql + ");";
        }
    }
}
